//http://icelab.com.au/articles/levelling-up-with-angularjs-building-a-reusable-click-to-edit-directive/
(function (define) {
    define([''], function () {
        var onClickEdit = function () {
            return {
                restrict: "A",
                replace: true,
                templateUrl: './web/js/src/Shush/ui/templates/onClickEdit.tpl.html',
                scope: {
                    value: "=onClickEdit",
                },
                controller: function($scope) {
                    $scope.view = {
                        editableValue: $scope.value,
                        editorEnabled: false
                    };

                    $scope.enableEditor = function() {
                        $scope.view.editorEnabled = true;
                        $scope.view.editableValue = $scope.value;
                    };

                    $scope.disableEditor = function() {
                        $scope.view.editorEnabled = false;
                    };

                    $scope.save = function() {
                        $scope.value = $scope.view.editableValue;
                        $scope.disableEditor();
                    };
                }
            };
        };

        return [ onClickEdit ];
    });
}(define));